package com.blame.javacup.hortalezablamers.utils.pases.simulador.engine;

import org.javahispano.javacup.model.command.CommandHitBall;
import org.javahispano.javacup.model.engine.GameSituations;

public class CommandHitBallSimulated implements Comparable<CommandHitBallSimulated> {
	protected GameSituations gs;
	protected CommandHitBall chb;
	protected Integer iterationDifference;
	
	public CommandHitBallSimulated(GameSituations gs, CommandHitBall chb,
			Integer iterationDifference) {
		super();
		this.gs = gs;
		this.chb = chb;
		this.iterationDifference = iterationDifference;
	}

	public CommandHitBall getChb() {
		return chb;
	}

	public Integer getIterationDifference() {
		return iterationDifference;
	}

	@Override
	public int compareTo(CommandHitBallSimulated other) {
		// ordenamos por diferencia de iteraciones y potencia
		if(gs.ballPosition().getY() <= 0)
			return (int)(other.getChb().getHitPower() * 100) - (int)(this.getChb().getHitPower() * 100);
		else
			return this.getIterationDifference() - other.getIterationDifference();
	}
	
	public String toString() {
		return "\nItDiff: " + this.getIterationDifference() + " - Ang: " + this.getChb().getAngle() + " - Pot: " + this.getChb().getHitPower() + " - AngV: " + this.getChb().getVerticalAngle();
	}

	@Override
	public boolean equals(Object o) {
		if(!(o instanceof CommandHitBallSimulated))
			return false;
		
		CommandHitBallSimulated other = (CommandHitBallSimulated) o;
		
		if(gs.ballPosition().getY() <= 0)
			return (int)(this.getChb().getHitPower() * 100) == (int)(other.getChb().getHitPower() * 100);
		else
			return this.getIterationDifference().equals(other.getIterationDifference());
	}
}
